#include "../begonia.h"
#include "scene.h"


void scene::pos(int tx,int ty,int tw,int th)
	{
		x=tx;y=ty;
		w=tw;h=th;
	}
void scene::size(int tx,int ty,int tw,int th,double tx1,double tx2,double ty1,double ty2)
	{
		x=tx;y=ty;
		w=tw;h=th;
		x1=tx1;x2=tx2;
		y1=ty1;y2=ty2;
	}
void scene::empty()
    {
        head.empty();
    }
void scene::move()
    {
        for(bullet *a=head.next,*a2;a!=&head;a=a2)
        {
            a2=a->next;
            if(a->move()&&a->judge()) missed=true;
        }
    }
void scene::show()
    {
        char s[64];
        if(w<scw)
        {
        	glViewport(x-picedge,y-picedge,w+picedge*2,h+picedge*2);
        	glMatrixMode(GL_PROJECTION);
        	glLoadIdentity();
            glOrtho(-1.0,1.0,-1.0,1.0, -1.0, 1.0);
        	glMatrixMode(GL_MODELVIEW);
            glColor3d(1.0,1.0,1.0);
            glBegin(GL_POLYGON);
                glVertex2d(-1.0,-1.0);
                glVertex2d(1.0,-1.0);
                glVertex2d(1.0,1.0);
                glVertex2d(-1.0,1.0);
            glEnd();
        	glViewport(x,y,w,h);
        	glMatrixMode(GL_PROJECTION);
        	glLoadIdentity();
            glOrtho(-1.0,1.0,-1.0,1.0, -1.0, 1.0);
        	glMatrixMode(GL_MODELVIEW);
            glColor3d(0.0,0.0,0.0);
            glBegin(GL_POLYGON);
                glVertex2d(-1.0,-1.0);
                glVertex2d(1.0,-1.0);
                glVertex2d(1.0,1.0);
                glVertex2d(-1.0,1.0);
            glEnd();
        }

    	glViewport(x,y,w,h);
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    	glOrtho(x1,x2,y1,y2, -1.0, 1.0);
    	glMatrixMode(GL_MODELVIEW);
        glColor3d(0.7,0.3,0.3);
        glEnable(GL_TEXTURE_2D);
        glBegin(GL_POLYGON);
            glTexCoord2d(0,0);glVertex2d(0,0);
            glTexCoord2d(1,0);glVertex2d(scw,0);
            glTexCoord2d(1,1);glVertex2d(scw,sch);
            glTexCoord2d(0,1);glVertex2d(0,sch);
        glEnd();
        glDisable(GL_TEXTURE_2D);
        glColor3d(1.0,0.5,0.5);
        drawcircle(px,py,pr);
        if(w<scw) for(bullet *a=head.next;a!=&head;a=a->next) a->show();
        else for(bullet *a=head.pre;a!=&head;a=a->pre) a->show();
    	if(score>=0)
    	{
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            glOrtho(0.0,w,0.0,h, -1.0, 1.0);
            glColor3d(1.0,1.0,1.0);
            sprintf(s,"%d",score);
            drawstring(0.0,0.0,s);
        }
    }
